package com.example.societiesSystem.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;


/*
 * @Description:统一返回结果
 */
@Data
@AllArgsConstructor
@ApiModel(value = "R对象", description = "统一返回结果")
public class R {

    //返回码
    @ApiModelProperty(value = "返回码")
    private Integer code;

    //返回消息
    @ApiModelProperty(value = "返回消息")
    private String msg;

    //返回数据
    @ApiModelProperty(value = "返回数据")
    private Object data;

    private R() {
    } //私有构造方法，让别人不能new 只能用我提供的方法 ,具有安全性

    public static R ok() {
        R r = new R();
        r.setCode(0);
        r.setMsg("成功");
        return r;
    }

    public static R error() {
        R r = new R();
        r.setCode(-1);
        r.setMsg("失败");
        return r;
    }


    public static R data(Object data) {
        R r = new R();
        r.setCode(0);
        r.setData(data);
        r.setMsg("成功");
        return r;
    }

    public static R messageData(String message, Object data) {
        R r = new R();
        r.setCode(0);
        r.setData(data);
        r.setMsg(message);
        return r;
    }

    public static R okMessage(String message) {
        R r = new R();
        r.setCode(0);
        r.setMsg(message);
        return r;
    }

    public static R errorMessage(String message) {
        R r = new R();
        r.setCode(-1);
        r.setMsg(message);
        return r;
    }


}
